package jblip.apps.clip;

import jblip.resources.Media;
import jblip.resources.Shortlink;
import jblip.resources.Subscription;
import jblip.resources.Update;
import jblip.resources.User;
import jblip.resources.UserPicture;
import jblip.resources.User.Sex;

public class ClipPrinter {

  public static void print(final User who) {
    System.out.print(who.getLogin());
    System.out.println(" (#" + who.getID() + "):");
    if (who.getLocation() != null) {
      System.out.println("  Location: \'" + who.getLocation() + '\'');
    }

    if (!who.getSex().equals(Sex.UNKNOWN)) {
      System.out.println("  Sex: " + who.getSex().toString());
    }

    if (who.getAvatar() != null) {
      System.out.print("  Avatar: ");
      System.out.println(who.getAvatar().getURL());
    } else if (who.getAvatarPath() != null) {
      System.out.print("  Avatar path: ");
      System.out.println(who.getAvatarPath());
    }

    if (who.getBackground() != null) {
      System.out.print("  Background: ");
      System.out.println(who.getBackground().getURL());
    } else if (who.getBackgroundPath() != null) {
      System.out.print("  Background path: ");
      System.out.println(who.getBackgroundPath());
    }
  }

  public static void print(Subscription s) {
    System.out.print("  [" + s.getTransport().toString() + "] ");
    System.out.print(s.getTrackingUserName());
    System.out.print(" tracks ");
    System.out.println(s.getTrackedUserName());
  }

  public static void print(final Update upd) {
    System.out.print("#" + upd.getId());
    System.out.print(" @" + upd.getCreatedAt());
    System.out.println(" via " + upd.getTransport().toString());

    System.out.print(upd.getSrcUserLogin());
    String dst_login = upd.getDstUserLogin();
    if (dst_login != null) {
      System.out.print(" > " + dst_login);
    }
    System.out.println(": " + upd.getBody());

    if (upd.getAttachedMoviePath() != null) {
      System.out.println("  Movie path: " + upd.getAttachedMoviePath());
    } else if (upd.getAttachedMovie() != null) {
      System.out.println("  Movie: " + upd.getAttachedMovie().getURL());
    }
    if (upd.getAttachedRecordingPath() != null) {
      System.out.println("  Recording path: " + upd.getAttachedRecordingPath());
    } else if (upd.getAttachedRecording() != null) {
      System.out.println("  Recording: " + upd.getAttachedRecording().getURL());
    }
    if (upd.getAttachedPicturesPath() != null) {
      System.out.println("  Pictures path: " + upd.getAttachedPicturesPath());
    } else if (upd.getAttachedPictures() != null) {
      int i = 1;
      for (Media m : upd.getAttachedPictures()) {
        System.out.println("  Picture #" + (i++) + ": " + m.getURL());
      }
    }
  }

  public static void print(final Shortlink link) {
    System.out.print("Shortlink #" + link.getID());
    System.out.print(" [" + link.getShortcode() + "]: ");
    System.out.println(link.getOriginalURL());
  }

  public static void print(final Media media) {
    System.out.print(media.getType().toString());
    System.out.print(" #" + media.getID() + ": ");
    System.out.print(media.getURL());
    if (media.getUpdate() == null && media.getUpdatePath() == null) {
      System.out.println();
    } else if (media.getUpdate() != null) {
      System.out.println(" [Update #" + media.getUpdate().getId() + "]");
    } else {
      System.out.println(" [Update path: " + media.getUpdatePath() + "]");
    } 
  }
  
  public static void print(final UserPicture pic) {
    System.out.print("User picture: ");
    System.out.print(pic.getID());
  }
}
